<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html> 
<head>
<title>Grep Sample</title>
<link rel="stylesheet" type="text/css" href="../../../docs/rotor.css">
</head>

<body>		


<h1> Grep Sample</h1>


<h2>Sample Overview</h2>


<p>This sample implements a simple grep text search sample utility.&nbsp; This sample demonstrates the 
use of regular expression functionality and the 
<b>System.Text.RegularExpressions.Regex </b>class.</p>


<h4>Usage</h4>


<blockquote>
  <pre>ngrep [-ismqleEt?] [-r replacePattern] pattern [files [files ...]]</pre>
</blockquote>


<p>The following table shows the command-line options used by the sample.</p>


<table border="1" width="90%">
  <tr>
    <th width="25%">Option</th>
    <th width="75%">Description</th>
  </tr>
  <tr>
    <td width="25%"><b>-?</b></td>
    <td width="75%">Shows usage information.</td>
  </tr>
  <tr>
    <td width="25%"><b>-e</b></td>
    <td width="75%">Shows only the part of the line matching the expression, not 
    the whole line.</td>
  </tr>
  <tr>
    <td width="25%"><b>-E</b></td>
    <td width="75%">Shows original and replacement expressions (with -r). 
    Expressions are separated with &quot;&quot; -&gt; &quot;&quot;.</td>
  </tr>
  <tr>
    <td width="25%"><b>-i</b></td>
    <td width="75%">Ignores case in search.</td>
  </tr>
  <tr>
    <td width="25%"><b>-l</b></td>
    <td width="75%">Shows lines only. Prevents showing filename or line number. 
    Cannot be used with <b>-m</b> option.</td>
  </tr>
  <tr>
    <td width="25%"><b>-m</b></td>
    <td width="75%">Shows only file names, not matching lines.</td>
  </tr>
  <tr>
    <td width="25%"><b>-q</b></td>
    <td width="75%">Specifies quiet mode. Shows only  summary data.</td>
  </tr>
  <tr>
    <td width="25%"><b>-r</b></td>
    <td width="75%">Replaces all matches with the given pattern.</td>
  </tr>
  <tr>
    <td width="25%"><b>-s</b></td>
    <td width="75%">Recurses into subdirectories.</td>
  </tr>
  <tr>
    <td width="25%"><b>-t</b></td>
    <td width="75%">Pretends to replace, but does not actually modify the file. 
    Use with the <b>-r</b> option.</td>
  </tr>
</table>



<h2>Sample Source and Build Output Locations</h2>


<p>The sample source is found in sscli20\samples\utilities\grep.&nbsp; </p>


<p>The source file is:</p>


<ul class="none">
  <li><a href="grep.cs">grep.cs</a></li>
</ul>


<p>The build output location is %_NTTREE%\samples\utilities\grep.&nbsp; 
The output file is an executable assembly named ngrep.exe.</p>


<h2>Building the Sample</h2>


<p>All samples are built from the buildall script.&nbsp;  </p>


<p>You can also build all the 
samples by switching to the root of the sample directory, sscli20\samples, and typing 
<code>build -c</code>.</p>


<p>You can build this specific sample  by switching to the sample directory and typing 
<code>build -c</code>.</p>


<h2>Running the Sample</h2>


<p>These steps require that the Shared Source CLI (SSCLI) be already built and 
functional.</p>


<ol>
  <li>Run  env.bat. </li>
  <li>Switch to the %_NTTREE%\samples\utilities\grep directory.</li>
  <li>Type the following command:<blockquote>


<p>clix ngrep.exe <i>pattern</i> <i>filename</i></p>


  </blockquote>


  </li>
</ol>
<blockquote>


<p>where <i>pattern</i> is a regular expression search pattern and <i>filename</i> 
is the name of the file to search.</p>


</blockquote>


<hr>


<p><i>Copyright (c) 2006 Microsoft Corporation. All rights reserved.</i></p>
</body> 
</html>